<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="demo">
        <h1>标题1</h1>
        <h2>标题2</h2>
    </div>
    <script>
        var demo = document.getElementById('demo')
        console.log(demo.innerText)//获取元素纯文本内容
        console.log(demo.innerHTML)//获取元素内部文本 + 标签
    </script>
</body>
</html>